//
//  ActivityDetailViewController.m
//  UI_TabBarTest1(豆瓣)
//
//  Created by dllo on 16/6/24.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "ActivityDetailViewController.h"

#define kWidth self.view.frame.size.width
#define kHeight self.view.frame.size.height

@interface ActivityDetailViewController ()

@end

@implementation ActivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createButton];
    [self createView];
}
/** 创建视图 */
-(void)createButton{
    self.title = self.activity.title;
    /** 返回按钮 */
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btn_nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonItemAction:)];
    self.navigationItem.leftBarButtonItem = backButtonItem;
    /** 分享按钮 */
    UIBarButtonItem *shareButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btn_nav_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonItemAction:)];
    self.navigationItem.rightBarButtonItem = shareButtonItem;
    
}

-(void)createView{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, kWidth - 40, 60)];
    [self.view addSubview:titleLabel];
    /** 色块,代码完成后去除 */
//    titleLabel.backgroundColor = [UIColor yellowColor];
    titleLabel.text = self.activity.title;
    titleLabel.font = [UIFont systemFontOfSize:20.0];
    
    NSURL *url = [NSURL URLWithString:self.activity.image];
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    /** 图片! */
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data]];
    imageView.frame = CGRectMake(20, 60, (kWidth - 40) * 0.33, 180);
    [self.view addSubview:imageView];
    
    UIImageView *timeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_date_blue"]];
    timeImageView.frame = CGRectMake(30 + (kWidth - 40) * 0.33, 60, 25, 25);
    [self.view addSubview:timeImageView];
    
    UIImageView *ownerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_sponsor_blue"]];
    ownerImageView.frame = CGRectMake(30 + (kWidth - 40) * 0.33, 90, 25, 25);
    [self.view addSubview:ownerImageView];
    
    UIImageView *categoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_catalog_blue"]];
    categoryImageView.frame = CGRectMake(30 + (kWidth - 40) * 0.33, 120, 25, 25);
    [self.view addSubview:categoryImageView];
    
    UIImageView *addressImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_spot_blue"]];
    addressImageView.frame = CGRectMake(30 + (kWidth - 40) * 0.33, 150, 25, 25);
    [self.view addSubview:addressImageView];
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(60 + (kWidth - 40) * 0.33, 60, (kWidth - 40) * 0.6 - 10, 25)];
    /** 色块,代码完成后去除 */
 //   timeLabel.backgroundColor = [UIColor yellowColor];
    NSString *beginTime = [self.activity.begin_time substringWithRange:NSMakeRange(5, 11)];
    NSString *endTime = [self.activity.end_time substringWithRange:NSMakeRange(5, 11)];
    timeLabel.text = [NSString stringWithFormat:@"%@ -- %@",beginTime,endTime];
    [self.view addSubview:timeLabel];
    
    UILabel *ownerLabel = [[UILabel alloc] initWithFrame:CGRectMake(60 + (kWidth - 40) * 0.33, 90, (kWidth - 40) * 0.6 - 15, 25)];
    ownerLabel.text = [self.activity.owner valueForKey:@"name"];
    [self.view addSubview:ownerLabel];
    
    UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(60 + (kWidth - 40) * 0.33, 120, (kWidth - 40) * 0.6 - 15, 25)];
    NSString *str = self.activity.category_name;
    categoryLabel.text = [NSString stringWithFormat:@"类型: %@",str];
    [self.view addSubview:categoryLabel];
    
    UILabel *addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(60 + (kWidth - 40) * 0.33, 150, (kWidth - 40) * 0.6 - 15, 45)];
    addressLabel.text = self.activity.address;
    addressLabel.numberOfLines = 0;
    [self.view addSubview:addressLabel];
//    addressLabel.backgroundColor = [UIColor yellowColor];
    
    UILabel *activityShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 240, kWidth - 40, 60)];
    activityShowLabel.text = @"活动介绍";
    activityShowLabel.font = [UIFont boldSystemFontOfSize:20.0];
    [self.view addSubview:activityShowLabel];
    
    UILabel *activityLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 290, kWidth - 40, kHeight - 290)];
    activityLabel.text = self.activity.content;
    activityLabel.numberOfLines = 0;
    [self.view addSubview:activityLabel];
    
}

-(void)backButtonItemAction:(UIBarButtonItem *)backButtonItem{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)shareButtonItemAction:(UIBarButtonItem *)shareButtonItem{
    NSLog(@"点击了分享");
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
